package com.ruoyi.omp.api.factory;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.omp.api.RemoteBillService;
import com.ruoyi.omp.api.domain.FeApartmentBill;
import com.ruoyi.omp.api.domain.FeBill;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author: cjie
 * @description: 账单信息降级处理
 * @date: 2021/9/23
 */
@Component
public class RemoteBillFactory implements FallbackFactory<RemoteBillService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteBillFactory.class);

    @Override
    public RemoteBillService create(Throwable throwable) {
        log.error("账单信息服务调用失败:{}", throwable.getMessage());
        return new RemoteBillService() {
            /**
             * 查询账单信息
             *
             * @param feBill 账单信息
             * @return
             */
            @Override
            public R<List<FeBill>> listBill(FeBill feBill) {
                return R.fail("查询账单信息失败:" + throwable.getMessage());
            }

            /**
             * 查询对应记录收费类型的最后一条账单信息
             *
             * @param feBill 账单信息
             * @return
             */
            @Override
            public R<FeBill> lastBill(FeBill feBill) {
                return R.fail("查询账单信息失败:" + throwable.getMessage());
            }

            /**
             * 新增账单
             *
             * @param feBill 账单信息
             * @return
             */
            @Override
            public R addBill(FeBill feBill) {
                return R.fail("新增账单失败:" + throwable.getMessage());
            }

            @Override
            public R addApartBill(FeApartmentBill feBill) {
                return R.fail("新增公寓账单失败:" + throwable.getMessage());
            }
        };
    }
}
